package rickyGame.game.perception
{
	import ricky.game.Actor;
	import ricky.game.action.Act2D;
	import ricky.game.perception.Percept;
	import ricky.game.perception.PerceptFactory;
	
	import rickyGame.config.unit.Unit;
	import rickyGame.game.GameState;
	import rickyGame.game.Player;
	import rickyGame.game.action.ai.SeekAi;

	/**
	 * 寻找敌人
	 */
	public class searchEnemy extends Percept
	{
		public function searchEnemy()
		{
			this._type="searchEnemy";
			PerceptFactory.register(searchEnemy);
		}
		
		override public function calculate(actor:Actor, par:Object=null):Act2D
		{
			actor.ai.currPercept=this.type;
//			actor.ai.lastPercept=
			var unit:Unit=actor.data;
			var arr:Array=GameState.inst.sceneManager.getGridAround(actor.gridX,actor.gridY,unit.rangeVisible,20);
			var target:Player;
			
			for each(var a:Actor in arr)
			{
				if(a.group!=actor.group) //搜索不是同一个阵营
				{
					target=a;
					break;
				}
			}

			var act:Act2D;
			if(target)
			{
				act=new SeekAi(actor,target);
			}
			
			return act;
			//actor.ai.aitree
		}
	}
}